package com.sse.task;

import com.alibaba.fastjson.JSONObject;
import com.sse.context.SseSessionHolder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Random;
import java.util.concurrent.TimeUnit;

/**
 * @title: LiveOilPricePushServer
 * @Author xu-xiang
 * @Date: 2024/1/26 15:50
 * @description: 实时气温推送
 */
//@Service
public class LiveTemperaturePushServer implements ScheduledPushServer {

    private static final Logger logger = LoggerFactory.getLogger(LiveTemperaturePushServer.class);

    @Override
    public Integer getScheduledTime() {
        return 6;
    }

    @Override
    public TimeUnit getTimeUnit() {
        return TimeUnit.SECONDS;
    }

    @Override
    public void run() {
        //模拟实时气温推送
        JSONObject shenzhenTemperature = new JSONObject();
        shenzhenTemperature.put("city", "深圳");
        shenzhenTemperature.put("Temperature", 20 + new Random().nextDouble() * 10 + "℃");
        SseSessionHolder.sendAll(shenzhenTemperature.toString());
    }
}
